{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-10-14T06:01:18.416199Z",
     "start_time": "2025-10-14T06:01:18.373816Z"
    }
   },
   "source": "#选择题:1.b 2.c 3.c  4.a  5.c  6.b  7.a  8.b",
   "outputs": [],
   "execution_count": 6
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-14T06:11:50.465679Z",
     "start_time": "2025-10-14T06:11:50.440223Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#程序分析:1.\n",
    "import random\n",
    "import math\n",
    "\n",
    "from adodbapi.examples.xls_read import driver\n",
    "\n",
    "n = random.randint(1, 100)  # 函数 random.randint(a,b) 返回从 a 到 b 之间随机选出的一个整数\n",
    "a, b, cnt = 1, 100, 0\n",
    "while a <= b:\n",
    "    cnt += 1\n",
    "    m = math.ceil((a + b) / 2)  # 函数 math.ceil(x) 的返回值为数值 x 的向上取整\n",
    "    if n < m:\n",
    "        b = m - 1\n",
    "    elif n==m:\n",
    "        break\n",
    "    else :\n",
    "        a = m+1\n",
    "\n",
    "print(cnt)\n"
   ],
   "id": "b40b222af998d2c4",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5\n"
     ]
    }
   ],
   "execution_count": 85
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-14T06:26:56.085214Z",
     "start_time": "2025-10-14T06:26:54.288177Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#程序分析2:\n",
    "n = int(input())\n",
    "S = 0\n",
    "sign = 1\n",
    "k = 1\n",
    "for i in range(1,n+1):\n",
    "    k = k * i\n",
    "    S += sign * k\n",
    "    sign = -sign\n",
    "print(S)\n"
   ],
   "id": "9691135ea17d4c7b",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-19\n"
     ]
    }
   ],
   "execution_count": 92
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-14T06:33:04.225103Z",
     "start_time": "2025-10-14T06:33:04.205909Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#程序分析3:\n",
    "def Change(radix, num):\n",
    "    g = []\n",
    "    while num != 0:\n",
    "        r = num % radix\n",
    "        num = num//radix\n",
    "        g.append(r)\n",
    "    ans = ''\n",
    "    t = ('A', 'B', 'C', 'D', 'E', 'F')\n",
    "    for x in range(len(g)):\n",
    "        if g[x] >= 10:\n",
    "            ans += t[g[x] - 10]\n",
    "        else:\n",
    "            ans += str(g[x])\n",
    "    return ans[::-1]\n",
    "print(Change(16, 12455))\n"
   ],
   "id": "f88e823cdabff89e",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "30A7\n"
     ]
    }
   ],
   "execution_count": 95
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-14T06:41:02.898812Z",
     "start_time": "2025-10-14T06:41:02.879513Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#程序分析4:\n",
    "def identical(L):\n",
    "    flag = 0\n",
    "    L.sort()\n",
    "    for i in range(len(L)-1):\n",
    "        if L[i]==L[i+1]:\n",
    "            flag = 1\n",
    "            break\n",
    "    if flag:\n",
    "        return True\n",
    "    else:\n",
    "        return False\n"
   ],
   "id": "c831b47767e4328d",
   "outputs": [],
   "execution_count": 102
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-14T06:47:31.593946Z",
     "start_time": "2025-10-14T06:47:31.564928Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#程序分析5:\n",
    "a = [5, 1, 2, 3, 5, 9, 6, 7, 4, 6, 8]\n",
    "maxlen = 1\n",
    "n = 1\n",
    "for i in range(1, len(a)):\n",
    "    if a[i]>a[i-1]:\n",
    "        n += 1\n",
    "        if maxlen <n:\n",
    "            maxlen = n\n",
    "    else:\n",
    "        n = 1\n",
    "print(maxlen)\n"
   ],
   "id": "bab4efd7e646b7ec",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5\n"
     ]
    }
   ],
   "execution_count": 103
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-14T07:08:52.137661Z",
     "start_time": "2025-10-14T07:08:52.070369Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#python数据分析:\n",
    "import pandas as pd\n",
    "import os\n",
    "\n",
    "drivers_df=pd.read_csv('drivers.csv')\n",
    "average_rating=drivers_df['rating'].mean()\n",
    "\n",
    "total_drivers = len(drivers_df)\n",
    "second_lang_count = drivers_df[drivers_df['second_language'] != 'no'].shape[0]\n",
    "second_lang_percentage = (second_lang_count / total_drivers) * 100\n",
    "\n",
    "ride_files = [f'rides_{i}.csv' for i in range(1, 5)]\n",
    "rides_dfs = []\n",
    "for file in ride_files:\n",
    "    if os.path.exists(file):\n",
    "        rides_dfs.append(pd.read_csv(file))\n",
    "\n",
    "all_rides = pd.concat(rides_dfs, ignore_index=True)\n",
    "total_rides = len(all_rides)\n",
    "success_rides = all_rides[all_rides['status'] == 'Success'].shape[0]\n",
    "success_rate = (success_rides / total_rides) * 100\n",
    "\n",
    "results = pd.DataFrame([\n",
    "    {'insight_type': 'average_driver_rating', 'value': round(average_rating, 2)},\n",
    "    {'insight_type': 'percentage_drivers_with_second_language', 'value': round(second_lang_percentage, 2)},\n",
    "    {'insight_type': 'ride_success_rate', 'value': round(success_rate, 2)}\n",
    "])\n",
    "results.to_csv('analysis_results.csv', index=False)"
   ],
   "id": "3d49c6c2d34ec7fe",
   "outputs": [],
   "execution_count": 107
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": [
    "#深度学习:\n",
    "1.对每批次数据在层与层之间进行标准化处理的技术\n",
    "2.忘了\n",
    "3.对计算出的梯度值进行限制范围处理的技术,用于解决 梯度爆炸问题\n",
    "4.是一种正则化策略,因为正则化用来防止过拟合与欠拟合\n",
    "5.弥补样本缺陷,防止过拟合\n",
    "6.忘了\n",
    "7.调度学习率能有效的防止，过拟合与欠拟合\n",
    "\n"
   ],
   "id": "12a8eef1d916608e"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-14T07:33:48.674543Z",
     "start_time": "2025-10-14T07:33:21.939398Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 假设我们用 60 天的价格预测第 61 天价格\n",
    "import numpy as np\n",
    "from tensorflow.keras.models import Sequential\n",
    "from tensorflow.keras.layers import LSTM, Dropout, Dense\n",
    "time_steps = 60\n",
    "features = 1\n",
    "samples = 200\n",
    "\n",
    "# 构造输入数据 (samples, time_steps, features)\n",
    "x_train = np.random.rand(samples, time_steps, features)  # 200个 60天股票价格\n",
    "y_train = np.random.rand(samples, 1)                     # 200个 对应的第61天股票价格\n",
    "x_test  = np.random.rand(10, time_steps, features)       # 测试\n",
    "\n",
    "stock_model = Sequential([LSTM(units=4, return_sequences=True, input_shape=(time_steps, features)),Dropout(rate=0.2),LSTM(units=4, return_sequences=False),  Dropout(rate=0.2),Dense(units=1)])\n",
    "stock_model.compile(loss='mean_squared_error',optimizer='adam')\n",
    "stock_model.fit(x_train, y_train,epochs=5,batch_size=16,verbose=0)\n",
    "\n",
    "print(stock_model.summary())\n",
    "predictions = stock_model.predict(x_test)\n",
    "print(predictions[:, -1])"
   ],
   "id": "b7c46a0858a7b6b",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Model: \"sequential\"\n",
      "_________________________________________________________________\n",
      " Layer (type)                Output Shape              Param #   \n",
      "=================================================================\n",
      " lstm (LSTM)                 (None, 60, 4)             96        \n",
      "                                                                 \n",
      " dropout (Dropout)           (None, 60, 4)             0         \n",
      "                                                                 \n",
      " lstm_1 (LSTM)               (None, 4)                 144       \n",
      "                                                                 \n",
      " dropout_1 (Dropout)         (None, 4)                 0         \n",
      "                                                                 \n",
      " dense (Dense)               (None, 1)                 5         \n",
      "                                                                 \n",
      "=================================================================\n",
      "Total params: 245 (980.00 Byte)\n",
      "Trainable params: 245 (980.00 Byte)\n",
      "Non-trainable params: 0 (0.00 Byte)\n",
      "_________________________________________________________________\n",
      "None\n",
      "1/1 [==============================] - 1s 1s/step\n",
      "[0.4161492  0.45163184 0.45144796 0.46192008 0.45863384 0.47789037\n",
      " 0.440202   0.4261995  0.38230568 0.4303093 ]\n"
     ]
    }
   ],
   "execution_count": 109
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
